def create_bullet(damage):
    return {"damage": damage}

def hurt_enemy(bullet, enemy):
    enemy["blood"] -= bullet["damage"]

def create_clip(capacity):
    return {"capacity": capacity, "current_list": []}

def save_bullets(clip, bullet):
    if len(clip["current_list"]) < clip["capacity"]:
        clip["current_list"].append(bullet)

def launch_bullet(clip):
    if len(clip["current_list"]) > 0:
        bullet = clip["current_list"][-1]
        clip["current_list"].pop()
        return bullet
    else:
        return None

def create_gun():
    return {"clip": None,  "state": "枪没有弹夹"}

def mounting_clip(gun, clip):
    if not gun["clip"]:
        gun["clip"] = clip

def shoot(gun, enemy):
    bullet = launch_bullet(gun["clip"])
    if bullet:
        hurt_enemy(bullet, enemy)
    else:
        print("没有子弹了，放了空枪...")

def create_person(name):
    return {"name": name, "blood": 100}

def install_bullet(person, clip, bullet):
    save_bullets(clip, bullet)

def install_clip(person, gun, clip):
    mounting_clip(gun, clip)
    gun["state"] = "枪当前有弹夹"

def take_gun(person, gun):
    person["gun"] = gun

def fire(person, enemy):
    shoot(person["gun"], enemy)


# 创建战士
soldier = create_person("老王")
# 创建弹夹
clip = create_clip(20)
# 上5发子弹
i = 0
while i < 5:
    # 创建子弹
    bullet = create_bullet(5)
    # 添加1发子弹
    install_bullet(soldier, clip, bullet)
    i += 1
# 展示弹夹
print(f"弹夹当前的子弹数量为: {len(clip['current_list'])}/{clip['capacity']}")
# 创建一支枪
gun = create_gun()
print(gun["state"])
# 装弹夹
install_clip(soldier, gun, clip)
print(gun["state"])
# 创建一个敌人
enemy = create_person("敌人")
print(f"{enemy['name']}剩余血量为: {enemy['blood']}")
# 士兵拿枪
take_gun(soldier, gun)
# 士兵开枪
fire(soldier, enemy)

print(f"弹夹当前的子弹数量为: {len(clip['current_list'])}/{clip['capacity']}")
print(f"{enemy['name']}剩余血量为: {enemy['blood']}")

fire(soldier, enemy)

print(f"弹夹当前的子弹数量为: {len(clip['current_list'])}/{clip['capacity']}")
print(f"{enemy['name']}剩余血量为: {enemy['blood']}")
